from rest_framework.decorators import api_view, authentication_classes, permission_classes
from libs.simple_responses import api_success
from account.models import PermissionModules


@api_view(['GET'])
@authentication_classes([])
@permission_classes([])
def modules(request):
    data = {
        'total': len(PermissionModules),
        'items': PermissionModules
    }
    return api_success(data=data)


@api_view(['GET'])
@authentication_classes([])
@permission_classes([])
def list(request):
    items = [p for m in PermissionModules for p in m['permissions']]
    data = {
        'total': len(items),
        'items': items
    }
    return api_success(data=data)
